﻿using Microsoft.EntityFrameworkCore;
using My.Domain.Issues;
using My.EntityFrameworkCore.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore;
using Volo.Abp.Specifications;

namespace My.EntityFrameworkCore.Issues
{
    public class IssueRepository : EfCoreRepository<EntityFrameworkCore.DefaultDbContext, Issue, Guid>, IIssueRepository
    {
        public IssueRepository(IDbContextProvider<EntityFrameworkCore.DefaultDbContext> dbContextProvider) : base(dbContextProvider)
        {
        }

        public async Task<int> GetIssueCountOfUserAsync(Guid userId)
        {
            var query = await GetQueryableAsync();
            return await query.Where(x => x.AssignedUserId == userId).CountAsync();
        }

        public async Task<List<Issue>> GetIssuesAsync(ISpecification<Issue> spec)
        {
            var query = await GetQueryableAsync();
            return await query.Where(spec.ToExpression()).ToListAsync();
        }
    }
}
